package cn.edu.scau.cmil.linwei.comprehensive.Controller;

import cn.edu.scau.cmil.linwei.comprehensive.Script.*;
import cn.edu.scau.cmil.linwei.comprehensive.util.DataIO;
import cn.edu.scau.cmil.linwei.comprehensive.util.StageManager;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.io.IOException;
import java.net.URL;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.ResourceBundle;

import static cn.edu.scau.cmil.linwei.comprehensive.Script.DataField.LoginedTeacher;
import static cn.edu.scau.cmil.linwei.comprehensive.Script.DataField.scoreData;

public class TeacherMainWindowsController implements Initializable {

    private boolean TipChoose;//存储Tip窗口的返回值

    public void setTipChoose(boolean tipChoose) {
        TipChoose = tipChoose;
    }



    public BorderPane borderPane;
    public Text userIDText;

    //用户修改密码的页面
    public VBox ChangePasswordPane;
    public PasswordField ChangePasswordOldPasswordField;
    public PasswordField ChangePasswordNewPasswordField;
    public PasswordField ChangePasswordComfirmPWPasswordField;
    public Text ChangePasswordTipText;
    public Button ChangePasswordButton;

    //用户修改密保问题的页面
    public VBox ChangeInitQuestionAndInitAnswerVBox;
    public Text ChangeInitQuestionAndInitAnswerOldQuestionText;
    public Text ChangeInitQuestionAndInitAnswerOldAnswerText;
    public TextField ChangeInitQuestionAndInitAnswerOldAnswerTextField;
    public Text ChangeInitQuestionAndInitAnswerNewQuestionText;
    public TextField ChangeInitQuestionAndInitAnswerNewQuestionTextField;
    public Text ChangeInitQuestionAndInitAnswerNewAnswerText;
    public TextField ChangeInitQuestionAndInitAnswerNewAnswerTextField;
    public Text ChangeInitQuestionAndInitAnswerTipText;
    public Button ChangeInitQuestionAndInitAnswerButton;

    //教师添加、删除课程的页面
    public VBox TeacherAddCoursePane;
    public ComboBox TeacherAddCourseComboBox;
    public Text TeacherAddCoursetipText;
    public Button TeacherAddCourseButton;

    //教师根据班级添加、删除学生的页面
    public VBox TeacherAddStudentPane;
    public ComboBox TeacherAddStudentCourseComboBox;
    public ComboBox TeacherAddStudentGradeComboBox;
    public ComboBox TeacherAddStudentMajorComboBox;
    public ComboBox TeacherAddStudentClassComboBox;
    public Text TeacherAddStudentTipText;
    public Button TeacherAddStudentButton;

    //教师录入、打印学生成绩的页面
    public VBox TeacherInputOrPrintStudentScorePane;
    public ComboBox TeacherInputOrPrintStudentScoreCourseComboBox;
    public ComboBox TeacherInputOrPrintStudentScoreGradeComboBox;
    public ComboBox TeacherInputOrPrintStudentScoreMajorComboBox;
    public ComboBox TeacherInputOrPrintStudentScoreClassComboBox;
    public Text TeacherInputOrPrintStudentScoreTipText;

    //管理员添加课程、专业、年级、白名单的页面
    public VBox AdminAddCourseOrMajorOrGradeOrWhitelistPane;
    public Text AdminAddCourseOrMajorOrGradeOrWhitelistText;
    public Text AdminAddCourseOrMajorOrGradeOrWhitelistTipText;
    public TextField AdminAddCourseOrMajorOrGradeOrWhitelistTextField;
    public Button AdminAddCourseOrMajorOrGradeOrWhitelistButton;

    //管理员添加班级的页面
    public VBox AdminAddClassPane;
    public Text AdminAddClassTipText;
    public ComboBox AdminAddClassGradeComboBox;
    public ComboBox AdminAddClassMajorComboBox;
    public ComboBox AdminAddClassNumComboBox;
    public Button AdminAddClassButton;

    //管理员删除年级、专业、课程、用户的界面
    public VBox AdminDelCoursePane;
    public Text AdminDelCourseText;
    public Text AdminDelCourseTipText;
    public ComboBox AdminDelCourseComboBox;
    public Button AdminDelCourseButton;

    //管理员查看用户信息的界面
    public VBox AdminWatchUserInformationPane;
    public Text AdminWatchUserInformationTipText;
    public TableView AdminWatchUserInformationTableView;
    public ScrollPane AdminWatchUserInformationScrollPane;
    public Text AdminWatchUserInformationDetailText;
    public TableColumn IDTableColumn;//ID
    public TableColumn PWTableColumn;//密码
    public TableColumn NameTableColumn;//姓名
    public TableColumn UserKindTableColumn;//用户类型
    public TableColumn InitQuestionTableColumn;//密保问题
    public TableColumn InitAnswerTableColumn;//密保答案

    //管理员查看白名单信息，可以删除白名单帐号
    public VBox AdminWatchWhitelistPane;
    public Text AdminWatchWhitelistTipText;
    public TableView AdminWatchWhitelistTableView;
    public TableColumn AdminWatchWhitelistIDTableColumn;
    public TableColumn AdminWatchWhitelistRegisteredTableColumn;
    public Button AdminWatchWhitelistLeftButton;
    public Button AdminWatchWhitelistRightButton;


    private String choosedCourse;
    private String choosedGrade;
    private String choosedMajor;
    private String choosedClass;

    public String getChoosedCourse() {
        return choosedCourse;
    }

    public void setChoosedCourse(String choosedCourse) {
        this.choosedCourse = choosedCourse;
    }

    public String getChoosedGrade() {
        return choosedGrade;
    }

    public void setChoosedGrade(String choosedGrade) {
        this.choosedGrade = choosedGrade;
    }

    public String getChoosedMajor() {
        return choosedMajor;
    }

    public void setChoosedMajor(String choosedMajor) {
        this.choosedMajor = choosedMajor;
    }

    public String getChoosedClass() {
        return choosedClass;
    }

    public void setChoosedClass(String choosedClass) {
        this.choosedClass = choosedClass;
    }



    //标题栏最小化、关闭、拖拽
    private double oldStageX,oldStageY,oldScreenX,oldScreenY;//点击时记录窗口的XY
    //最小化
    public void MinButtonClicked(){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.setIconified(true);
    }//设置最小化按钮点击时发生的活动选项
    //关闭
    public void CloseButtonClicked(){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.close();
    }//设置关闭按钮点击时发生的活动选项
    //鼠标拖拽
    public void MousePressed(MouseEvent event){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        oldStageX = stage.getX();//事件相对于MouseEvent源的原点的水平位置，即获取当前鼠标位置
        oldStageY = stage.getY();//事件相对于MouseEvent源的原点的垂直位置，即获取当前鼠标位置
        oldScreenX = event.getScreenX();//返回事件的绝对水平位置，即获取窗口左上角位置
        oldScreenY = event.getScreenY();//返回事件的绝对垂直位置，即获取窗口左上角位置
    }

    public void MouseDragged(MouseEvent event){
        Stage stage = (Stage) borderPane.getScene().getWindow();
        stage.setX(event.getScreenX()-oldScreenX+oldStageX);
        stage.setY(event.getScreenY()-oldScreenY+oldStageY);
    }



    //页面转换
    public void CloseTeacherMainWindows(){
        Stage stage = (Stage)borderPane.getScene().getWindow();//通过布局获取场景再获取舞台
        StageManager.STAGEMAP.put("TeacherMainWindows",stage);//保存舞台
        StageManager.CONTROLLERMAP.put("TeacherMainWindowsController",this);//保存控制器
        stage.close();//关闭舞台
    }//关闭当前页面

    public void SaveTeacherMainWindows(){
        Stage stage = (Stage)borderPane.getScene().getWindow();//通过布局获取场景再获取舞台
        StageManager.STAGEMAP.put("TeacherMainWindows",stage);//保存舞台
        StageManager.CONTROLLERMAP.put("TeacherMainWindowsController",this);//保存控制器
    }//保存当前页面的舞台和控制器到MAP中
    //1.注销
    public void GoBack(){//返回登录界面
        CloseTeacherMainWindows();//关闭当前界面
        openLoginWindows();//打开登录界面
    }//注销

    public void openLoginWindows() {
        Stage stage = StageManager.STAGEMAP.get("Login");//读取Login的引用，打开Login界面
        StageManager.STAGEMAP.remove("Login");//在MAP中删除Login页面的Stage
        StageManager.CONTROLLERMAP.remove("Login");//在MAP中删除Login页面的Controller
        stage.show();
    }//打开登录界面

    //2.弹出置顶的提示界面
    private String TipText;
    private String ButtonLeftText;
    private String ButtonRightText;

    public String getTipText() {
        return TipText;
    }

    public String getButtonLeftText() {
        return ButtonLeftText;
    }

    public String getButtonRightText() {
        return ButtonRightText;
    }

    public void openTipWindows(String TipText,String ButtonLeftText,String ButtonRightText) throws IOException {
        SaveTeacherMainWindows();//必须保存本控制器，否则报错
        this.TipText = TipText;
        this.ButtonLeftText = ButtonLeftText;
        this.ButtonRightText = ButtonRightText;
        Stage stage = new Stage();
        BorderPane root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmil/linwei/comprehensive/FXML/Tip.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.showAndWait();
    }

    //实现操作用到的工具函数
    public boolean StringNotExistInArraylist(String tmp,ArrayList chooselist){
        for(int i=0;i<chooselist.size();i++){
            if(tmp.equals(chooselist.get(i))){
                return false;
            }
        }
        return true;//如果没有找到相等的值，证明没添加过
    }//如果String不存在于数组中，返回true

    //【下面是个人中心操作对应的实现】
    //1.修改密码
    public void ChangePasswordOnAction() throws IOException {
        String oldPW = ChangePasswordOldPasswordField.getText();
        String newPW = ChangePasswordNewPasswordField.getText();
        String confirmPW = ChangePasswordComfirmPWPasswordField.getText();
        if(oldPW.equals(DataField.LoginedUser.PW)){//如果密码验证对了
            if(newPW.equals(confirmPW)){//如果两个新密码相同
                if(newPW.length()>10){//如果长度超过10
                    ChangePasswordTipText.setText("密码不能长于十个字符");
                }
                else if(newPW.length() == 0){//如果长度为0
                    ChangePasswordTipText.setText("新密码不能为空");
                }
                else{
                    DataField.LoginedUser.PW = newPW;//更改密码
                    DataIO.UserWrite();//把密码修改保存到本地
                    ChangePasswordOldPasswordField.clear();
                    ChangePasswordNewPasswordField.clear();
                    ChangePasswordComfirmPWPasswordField.clear();
                    ChangePasswordTipText.setText("修改密码成功");
                }

            }
            else{
                ChangePasswordTipText.setText("两次输入的新密码不一致");
            }
        }
        else{
            ChangePasswordTipText.setText("您输入的原密码错误");
        }
    }//修改密码OnAction

    public void ChangePassword(){
        InitPanes();//所有的pane设为不可见不可用
        ChangePasswordPane.setVisible(true);//可见
        ChangePasswordPane.setDisable(false);//可用
        ChangePasswordTipText.setText("");
        ChangePasswordButton.setText("确定修改");
        ChangePasswordButton.setOnAction(e-> {
            try {
                ChangePasswordOnAction();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        });
        System.out.println("用户修改密码");
    }//修改密码
    //2.修改密保问题
    public void ChangeInitQuestionAndInitAnswerOnAction() throws IOException {
        String OldAnswer = ChangeInitQuestionAndInitAnswerOldAnswerTextField.getText();
        String NewQuestion = ChangeInitQuestionAndInitAnswerNewQuestionTextField.getText();
        String NewAnswer = ChangeInitQuestionAndInitAnswerNewAnswerTextField.getText();
        if(OldAnswer.equals(DataField.LoginedUser.InitQuestion)){
            //如果输入的密保答案相符
            if( NewQuestion.length()>10 || NewAnswer.length()>10 ){
                //如果输入的密保问题或答案长度超过10
                ChangeInitQuestionAndInitAnswerTipText.setText("输入的密保问题及答案的长度不能超过10");
            }
            else if(NewQuestion.length()==0 ||NewAnswer.length() == 0 ){
                //如果输入的密保问题或答案长度为0
                ChangeInitQuestionAndInitAnswerTipText.setText("输入的密保问题及答案不能为空");
            }
            else{//如果密保问题和答案都合法
                DataField.LoginedUser.InitQuestion = NewQuestion;
                DataField.LoginedUser.InitAnswer = NewAnswer;
                DataIO.UserWrite();
                ChangeInitQuestionAndInitAnswerOldQuestionText.setText("原密保问题："+DataField.LoginedUser.InitQuestion);
                ChangeInitQuestionAndInitAnswerOldAnswerTextField.clear();
                ChangeInitQuestionAndInitAnswerNewQuestionTextField.clear();
                ChangeInitQuestionAndInitAnswerNewAnswerTextField.clear();
                ChangeInitQuestionAndInitAnswerTipText.setText("修改成功");
            }
        }
        else{
            ChangeInitQuestionAndInitAnswerTipText.setText("输入的密保答案有误");
        }
    }//修改密保问题OnAction

    public void ChangeInitQuestionAndInitAnswer(){
        InitPanes();//所有的pane设为不可见不可用
        ChangeInitQuestionAndInitAnswerVBox.setVisible(true);//可见
        ChangeInitQuestionAndInitAnswerVBox.setDisable(false);//可用
        ChangeInitQuestionAndInitAnswerOldQuestionText.setText("原密保问题："+DataField.LoginedUser.InitQuestion);
        ChangeInitQuestionAndInitAnswerOldAnswerText.setText("原密保答案：");
        ChangeInitQuestionAndInitAnswerNewQuestionText.setText("新密保问题：");
        ChangeInitQuestionAndInitAnswerNewAnswerText.setText("新密保答案：");
        ChangeInitQuestionAndInitAnswerTipText.setText("");
        ChangeInitQuestionAndInitAnswerButton.setText("确定修改");
        ChangeInitQuestionAndInitAnswerButton.setOnAction(e-> {
            try {
                ChangeInitQuestionAndInitAnswerOnAction();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        });
        System.out.println("用户修改密保问题");
    }//修改密保问题

    //【下面是学生操作对应的实现】
    //查看自己成绩
    public void openStudentReportWindows() throws IOException {
        Stage stage = new Stage();
        BorderPane root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmil/linwei/comprehensive/FXML/StudentReportWindows.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.show();
    }//打开成绩报告页面

    public void StudentWatchScore() throws IOException {
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("1")){
            CloseTeacherMainWindows();
            openStudentReportWindows();
        }
        //如果不是教师，什么都不能做
    }//学生查看成绩，调用上面的openStudentReportWindows()

    //【下面是教师操作对应的实现】
    //添加课程
    public void TeacherAddCourseComboBoxPrepared(){
        ArrayList<String> teachedcourse = LoginedTeacher.teachCourse;
        String tmp ;
        String tmp2;
        bigfor:for(int i = 0;i<DataField.courseList.size(); i++){
            tmp = DataField.courseList.get(i);
            for(int j = 0;j<teachedcourse.size();j++){//在已添加的课程中寻找是否添加过本门课程
                tmp2 = teachedcourse.get(j);
                //tmp 为准备添加的课程，tmp2为已经添加过的课程
                if(tmp.equals(tmp2)){//如果相等，证明这门课添加过，不用加进可选列表
                    continue bigfor;
                }
            }
            //如果没有在上面的for中continue，则可以执行到这里，把tmp这门课添加进选择列表中
            TeacherAddCourseComboBox.getItems().add(tmp);
        }
    }//为添加课程的选项准备数据

    public void TeacherAddCourseAction(){
        //检查是否有填写。如果没有填写进行提示
        if(TeacherAddCourseComboBox.getValue() == null){
            TeacherAddCoursetipText.setText("请填写选项");
            return;
        }
        String course = (String)TeacherAddCourseComboBox.getValue();
        LoginedTeacher.teachCourse.add(course);

        try{
            DataIO.TeacherWrite();
        }
        catch (IOException e){ System.out.println("Teacher.txt写入失败"+e); }

        TeacherAddCoursetipText.setText("课程 "+TeacherAddCourseComboBox.getValue()+" 开设成功");
        TeacherAddCourseComboBox.getItems().clear();
        TeacherAddCourseComboBoxPrepared();
    }//把选项中的课程添加到教师的数据中，并写入文件

    public void TeacherAddCourse(){
        //步骤：
        //1.寻找没有添加进教师的课程，添加进可选择的列表里
        //2.选择课程后，点击添加，课程加进Teacher里的courselist
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("2")){
            TeacherAddCoursePane.setVisible(true);//可见
            TeacherAddCoursePane.setDisable(false);//可用
            TeacherAddCourseComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
            TeacherAddCourseComboBoxPrepared();
            TeacherAddCoursetipText.setText("");
            TeacherAddCourseButton.setText("确定开设");
            TeacherAddCourseButton.setOnAction(e->TeacherAddCourseAction());
            System.out.println("教师添加课程");
            System.out.println("教师目前的课程有：");
            for(int i = 0; i< LoginedTeacher.teachCourse.size(); i++){
                System.out.print(LoginedTeacher.teachCourse.get(i)+"，");
            }
        }
        //如果不是教师，什么都不能做

    }//教师为自己添加课程

    //删除课程
    public void TeacherDelCourseComboBoxPrepared(){
        ArrayList<String> teachedcourse = LoginedTeacher.teachCourse;
        //把教师上的所有课添加进选择列表中
        TeacherAddCourseComboBox.getItems().addAll(teachedcourse);
    }//为删除课程的选项准备数据

    public boolean isNobodyinCourse(String coursename){
        for(Score sc:scoreData){
            if(sc.CourseName.equals(coursename)){
                return false;
            }
        }
        return true;//如果课程里面没人，返回true
    }

    public void TeacherDelCourseAction(){
        //检查是否有填写。如果没有填写进行提示
        if(TeacherAddCourseComboBox.getValue() == null){
            TeacherAddCoursetipText.setText("请填写选项");
            return;
        }
        String course = (String)TeacherAddCourseComboBox.getValue();
        for(int i = 0; i< LoginedTeacher.teachCourse.size(); i++){
            if(LoginedTeacher.teachCourse.get(i).equals(course)){//找到目标。remove移除
                if(isNobodyinCourse(course)){//没人上课
                    LoginedTeacher.teachCourse.remove(i);
                    i-=1;
                    break;
                }
                else{//有人上课，二次确认
                    TeacherAddCoursetipText.setText("本课程已有学生上课，无法关闭");
                    return;
                }
            }
        }
        try{
            DataIO.TeacherWrite();
        }
        catch (IOException e){ System.out.println("Teacher.txt写入失败"+e); }

        TeacherAddCoursetipText.setText("课程 "+TeacherAddCourseComboBox.getValue()+" 关闭成功");
        TeacherAddCourseComboBox.getItems().clear();
        TeacherDelCourseComboBoxPrepared();
    }//把选项中的课程从教师的数据中删除，并写入文件

    public void TeacherDelCourse(){
        //步骤：
        //1.寻找添加进教师的课程，添加进可选择的列表里
        //2.选择课程后，点击添加，课程加进Teacher里的courselist
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("2")){
            TeacherAddCoursePane.setVisible(true);//可见
            TeacherAddCoursePane.setDisable(false);//可用
            TeacherAddCourseComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
            TeacherDelCourseComboBoxPrepared();
            TeacherAddCoursetipText.setText("");
            TeacherAddCourseButton.setText("确定关闭");
            TeacherAddCourseButton.setOnAction(e->TeacherDelCourseAction());
            System.out.println("教师删除课程");
            System.out.println("教师目前的课程有：");
            for(int i = 0; i< LoginedTeacher.teachCourse.size(); i++){
                System.out.print(LoginedTeacher.teachCourse.get(i)+"，");
            }
        }
        //如果不是教师，什么都不能做

    }//教师删除自己的课程

    //添加学生
    public void TeacherAddStudentCourseComboBoxPrepared(){
        TeacherAddStudentCourseComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        TeacherAddStudentGradeComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentMajorComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentClassComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentCourseComboBox.getItems().addAll(LoginedTeacher.teachCourse);
    }//为课程ComboBox准备选项

    public void TeacherAddStudentCourseComboBoxOnAction(){
        TeacherAddStudentGradeComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        TeacherAddStudentMajorComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentClassComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentGradeComboBox.getItems().addAll(DataField.gradeList);
    }//为年级ComboBox准备选项

    public void TeacherAddStudentGradeComboBoxOnAction(){
        TeacherAddStudentMajorComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        TeacherAddStudentClassComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentMajorComboBox.getItems().addAll(DataField.majorList);
    }//为专业ComboBox准备选项

    public void TeacherAddStudentMajorComboBoxOnAction(){
        TeacherAddStudentClassComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        //TeacherAddStudentGradeComboBox.getItems().addAll(DataField.majorList);
        //找到目标年级、专业的班级，然后在scorelist中寻找这个班
        //PS：无须对教师名进行匹配，这样的话如果这个班上过某门课，这门课的其他老师也无法添加这个班给自己
        String grade = (String)TeacherAddStudentGradeComboBox.getValue();
        String major = (String)TeacherAddStudentMajorComboBox.getValue();
        StudentClass sc;
        for(int i = 0;i<DataField.classList.size(); i++){
            sc = DataField.classList.get(i);
            if(sc.StudentGrade.equals(grade) && sc.StudentMajor.equals(major)){//如果年级和专业相同
                TeacherAddStudentClassComboBox.getItems().add(sc.StudentClass);//加入可选列表
            }//big if
        }//for

    }//根据年级、专业，为班级ComboBox准备选项

    public boolean isCreatedStudentScore(String studentID,String teacher, String coursename, ArrayList<Score> scorelist){
        for(Score sc:scorelist){
            if(sc.StudentID.equals(studentID) && sc.TeacherName.equals(teacher) && sc.CourseName.equals(coursename)){
                //如果出现相同的score，证明该学生在这门课上已经创建过score，返回值为真
                return true;
            }
        }
        return false;
    }//在数组中搜索是否存在学号、教师、课程名与形参相同的score，如果存在返回true

    public void TeacherAddStudentAction(){
        //检查是否有填写。如果没有填写进行提示
        if(TeacherAddStudentCourseComboBox.getValue() == null||
                TeacherAddStudentGradeComboBox.getValue() == null||
                TeacherAddStudentMajorComboBox.getValue() == null||
                TeacherAddStudentClassComboBox.getValue() == null){
            TeacherAddStudentTipText.setText("请填写选项");
            return;
        }
        String course = (String)TeacherAddStudentCourseComboBox.getValue();
        String grade = (String)TeacherAddStudentGradeComboBox.getValue();
        String major = (String)TeacherAddStudentMajorComboBox.getValue();
        String classes = (String)TeacherAddStudentClassComboBox.getValue();
        Student student ;
        int num = 0;
        //根据四个信息，在studentlist中寻找符合班级条件的所有学生，给所有学生建立一个该course的对应的score放入数据链中
        for(int i = 0 ;i<DataField.studentData.size(); i++){
            student = DataField.studentData.get(i);
            if(student.myclass.StudentGrade.equals(grade) &&
                    student.myclass.StudentMajor.equals(major) &&
                    student.myclass.StudentClass.equals(classes)){
                //如果找到了符合条件的该班级学生
                //如果这位学生没有创建score，那么建立score并加入到数据链中
                if(isCreatedStudentScore(student.ID,LoginedTeacher.Name,course,scoreData)){//传入教师名，课程名，判断该学生是否有创建score结点
                    continue;//如果创建了score，那么进行下一位学生的操作
                }
                Score score = new Score(student.ID,student.Name,
                        student.myclass.StudentGrade,student.myclass.StudentMajor,student.myclass.StudentClass,
                        LoginedTeacher.Name,course,0,0,0,0,0);
                scoreData.add(score);
                num++;
            }//if
        }

        try{
            DataIO.ScoreWrite();
        }
        catch (IOException e){ System.out.println("Score.txt写入失败"+e); }

        TeacherAddStudentTipText.setText(grade+" 级"+major+"专业"+classes+"班"+num+"名学生添加成功");
        TeacherAddStudentCourseComboBoxPrepared();
    }//把选项中的课程添加到教师的数据中，文件写入操作未可用！！！

    public void TeacherAddStudent(){
        //步骤：
        //1.寻找所有符合课程、年级、专业、班级号的学生
        //2.为所有学生创建一个score，并加入scorelist中
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("2")){
            TeacherAddStudentPane.setVisible(true);//可见
            TeacherAddStudentPane.setDisable(false);//可用
            TeacherAddStudentCourseComboBoxPrepared();//为第一个选项框准备选项
            TeacherAddStudentTipText.setText("");
            TeacherAddStudentButton.setText("确定添加");
            TeacherAddStudentButton.setOnAction(e->TeacherAddStudentAction());
            TeacherAddStudentCourseComboBox.setOnAction(e->TeacherAddStudentCourseComboBoxOnAction());
            TeacherAddStudentGradeComboBox.setOnAction(e->TeacherAddStudentGradeComboBoxOnAction());
            TeacherAddStudentMajorComboBox.setOnAction(e->TeacherAddStudentMajorComboBoxOnAction());
            System.out.println("教师添加学生班级");
            System.out.println("教师目前学生的score有：");
            for(int i = 0; i< scoreData.size(); i++){
                Score sc = scoreData.get(i);
                if(sc.TeacherName.equals(LoginedTeacher.Name)){
                    System.out.print(sc.StudentName+"，");
                }
            }
            System.out.println();
        }//if
        //如果不是教师，什么都不能做
    }//教师根据课名、班级、专业、班级添加学生

    //删除学生
    private ArrayList<Score> TeacherDelStudentSearchlist;

    public void TeacherDelStudentCourseComboBoxPrepared(){
        TeacherAddStudentCourseComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        TeacherAddStudentGradeComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentMajorComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentClassComboBox.getItems().clear();//clear其他选项框的内容
        String coursename;
        TeacherDelStudentSearchlist = null;
        System.gc();
        TeacherDelStudentSearchlist = new ArrayList<>();
        ArrayList<String> courselist = new ArrayList<>();
        for(int i = 0;i<DataField.LoginedTeacher.teachCourse.size();i++){
            //把这位教师教授课程中，有学生上课的课程加入选项列表
            coursename = DataField.LoginedTeacher.teachCourse.get(i);
            Score score;
            for(int j =0;j<DataField.scoreData.size();j++){
                score = DataField.scoreData.get(j);
                if(score.CourseName.equals(coursename) && score.TeacherName.equals(DataField.LoginedTeacher.Name)){
                    if(StringNotExistInArraylist(score.CourseName,courselist)){//如果不在已添加列表中，加入
                        courselist.add(coursename);
                        TeacherDelStudentSearchlist.add(score);
                    }
                    /*
                    boolean flag = false;
                    String tmp;
                    for(int z = 0;z<courselist.size();z++){
                        tmp = courselist.get(z);
                        if(tmp.equals(score.CourseName)){
                            flag = true;//如果已存在那么就true
                            break;
                        }
                    }
                    if(flag == false){//如果不存在，那么可以添加
                        courselist.add(coursename);
                        TeacherDelStudentSearchlist.add(score);
                    }
                    */

                }
            }
        }
        TeacherAddStudentCourseComboBox.getItems().addAll(courselist);
    }//为课程ComboBox准备选项

    public void TeacherDelStudentCourseComboBoxOnAction(){
        TeacherAddStudentGradeComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        TeacherAddStudentMajorComboBox.getItems().clear();//clear其他选项框的内容
        TeacherAddStudentClassComboBox.getItems().clear();//clear其他选项框的内容
        ArrayList<String> preparedgrade = new ArrayList<>();
        ArrayList<Score> tmpSearchlist = new ArrayList<>();
        Score score;
        for(int i = 0;i<TeacherDelStudentSearchlist.size();i++){
            score = TeacherDelStudentSearchlist.get(i);
            String tmp;
            boolean flag = false;
            for(int j = 0;j<preparedgrade.size();j++){
                tmp = preparedgrade.get(j);
                if(score.StudentGrade.equals(tmp)){//如果已经添加进了列表里，flag = true，查找下一个score
                    flag = true;
                    break;
                }
            }
            if(flag == false){
                preparedgrade.add(score.StudentGrade);
                tmpSearchlist.add(score);
            }
            TeacherAddStudentGradeComboBox.getItems().addAll(preparedgrade);
            TeacherDelStudentSearchlist = null;
            System.gc();
            TeacherDelStudentSearchlist = tmpSearchlist;
        }
    }//为年级ComboBox准备选项

    public void TeacherDelStudentGradeComboBoxOnAction(){
        TeacherAddStudentMajorComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        TeacherAddStudentClassComboBox.getItems().clear();//clear其他选项框的内容
        //TeacherAddStudentMajorComboBox.getItems().addAll(DataField.majorList);
        ArrayList<String> preparedmajor = new ArrayList<>();
        ArrayList<Score> tmpSearchlist = new ArrayList<>();
        Score score;
        for(int i = 0;i<TeacherDelStudentSearchlist.size();i++){
            score = TeacherDelStudentSearchlist.get(i);
            String tmp;
            boolean flag = false;
            for(int j = 0;j<preparedmajor.size();j++){
                tmp = preparedmajor.get(j);
                if(score.StudentMajor.equals(tmp)){//如果已经添加进了列表里，flag = true，查找下一个score
                    flag = true;
                    break;
                }
            }
            if(flag == false){
                preparedmajor.add(score.StudentMajor);
                tmpSearchlist.add(score);
            }
            TeacherAddStudentMajorComboBox.getItems().addAll(preparedmajor);
            TeacherDelStudentSearchlist = null;
            System.gc();
            TeacherDelStudentSearchlist = tmpSearchlist;
        }
    }//为专业ComboBox准备选项

    public void TeacherDelStudentMajorComboBoxOnAction(){
        TeacherAddStudentClassComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        //找到目标年级、专业的班级，然后在scorelist中寻找这个班
        //PS：无须对教师名进行匹配，这样的话如果这个班上过某门课，这门课的其他老师也无法添加这个班给自己
        String grade = (String)TeacherAddStudentGradeComboBox.getValue();
        String major = (String)TeacherAddStudentMajorComboBox.getValue();

        ArrayList<String> preparedclass = new ArrayList<>();
        ArrayList<Score> tmpSearchlist = new ArrayList<>();
        Score score;
        for(int i = 0;i<TeacherDelStudentSearchlist.size();i++){
            score = TeacherDelStudentSearchlist.get(i);
            String tmp;
            boolean flag = false;
            for(int j = 0;j<preparedclass.size();j++){
                tmp = preparedclass.get(j);
                if(score.StudentClass.equals(tmp)){//如果已经添加进了列表里，flag = true，查找下一个score
                    flag = true;
                    break;
                }
            }
            if(flag == false){
                preparedclass.add(score.StudentClass);
                tmpSearchlist.add(score);
            }
            TeacherAddStudentClassComboBox.getItems().addAll(preparedclass);
            TeacherDelStudentSearchlist = null;
            System.gc();
            TeacherDelStudentSearchlist = tmpSearchlist;
        }
    }//根据年级、专业，为班级ComboBox准备选项

    public void TeacherDelStudentAction(){
        //检查是否有填写。如果没有填写进行提示
        if(TeacherAddStudentCourseComboBox.getValue() == null||
                TeacherAddStudentGradeComboBox.getValue() == null||
                TeacherAddStudentMajorComboBox.getValue() == null||
                TeacherAddStudentClassComboBox.getValue() == null){
            TeacherAddStudentTipText.setText("请填写选项");
            return;
        }
        String course = (String)TeacherAddStudentCourseComboBox.getValue();
        String grade = (String)TeacherAddStudentGradeComboBox.getValue();
        String major = (String)TeacherAddStudentMajorComboBox.getValue();
        String classes = (String)TeacherAddStudentClassComboBox.getValue();
        Score score;
        int num = 0;
        //根据四个信息，删除这个班级的学生，在该课程的所有score结点
        //对sccorelist中所有符合年级、专业、班级、课名、教师名的结点，给所有学生删除这个score结点
        for(int i = 0 ;i<DataField.scoreData.size(); i++){
            score = DataField.scoreData.get(i);
            if(score.CourseName.equals(course) &&//课名
                    score.TeacherName.equals(DataField.LoginedTeacher.Name) &&//老师名
                    score.StudentGrade.equals(grade) &&//年级
                    score.StudentMajor.equals(major) &&//专业
                    score.StudentClass.equals(classes) ){//班级
                //如果找到了符合条件的该班级学生的score，删除
                scoreData.remove(i);
                num++;
                i-=1;
            }//if
        }

        try{
            DataIO.ScoreWrite();
        }
        catch (IOException e){ System.out.println("Score.txt写入失败"+e); }

        TeacherAddStudentTipText.setText(grade+" 级"+major+"专业"+classes+"班"+num+"名学生移除成功");
        TeacherAddStudentCourseComboBoxPrepared();
    }//把选项中的课程添加到教师的数据中，文件写入操作未可用！！！

    public void TeacherDelStudent(){
        //步骤：
        //1.在scorelist中查找课名、年级、专业、班级对应的学生score结点并删除这些结点

        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("2")){
            TeacherAddStudentPane.setVisible(true);//可见
            TeacherAddStudentPane.setDisable(false);//可用
            TeacherDelStudentCourseComboBoxPrepared();//为第一个选项框准备选项
            TeacherAddStudentTipText.setText("");
            TeacherAddStudentButton.setText("确定删除");
            TeacherAddStudentButton.setOnAction(e->TeacherDelStudentAction());
            TeacherAddStudentCourseComboBox.setOnAction(e->TeacherDelStudentCourseComboBoxOnAction());
            TeacherAddStudentGradeComboBox.setOnAction(e->TeacherDelStudentGradeComboBoxOnAction());
            TeacherAddStudentMajorComboBox.setOnAction(e->TeacherDelStudentMajorComboBoxOnAction());
            System.out.println("教师删除学生班级");
            System.out.println("教师目前学生的score有：");
            for(int i = 0; i< scoreData.size(); i++){
                Score sc = scoreData.get(i);
                if(sc.TeacherName.equals(LoginedTeacher.Name)){
                    System.out.print(sc.StudentName+"，");
                }
            }
            System.out.println();
        }//if
        //如果不是教师，什么都不能做
    }//教师根据课名、班级、专业、班级删除学生

    //录入/打印学生成绩
    public void TeacherInputOrPrintStudentScoreCourseComboBoxPrepared(){
        TeacherInputOrPrintStudentScoreCourseComboBox.getItems().clear();//先clear再准备数据，防止重复塞数据入选项中
        TeacherInputOrPrintStudentScoreGradeComboBox.getItems().clear();//clear其他选项框的内容
        TeacherInputOrPrintStudentScoreMajorComboBox.getItems().clear();//clear其他选项框的内容
        TeacherInputOrPrintStudentScoreClassComboBox.getItems().clear();//clear其他选项框的内容
        TeacherInputOrPrintStudentScoreCourseComboBox.getItems().addAll(LoginedTeacher.teachCourse);
    }//为课程ComboBox准备选项

    public void TeacherInputOrPrintStudentScoreCourseComboBoxOnAction(){//清空后面的选项，记录当前选项，根据老师名、课名从ScoreData查找参与本课程的年级
        choosedCourse = (String) TeacherInputOrPrintStudentScoreCourseComboBox.getValue();
        TeacherInputOrPrintStudentScoreGradeComboBox.getItems().clear();
        TeacherInputOrPrintStudentScoreMajorComboBox.getItems().clear();
        TeacherInputOrPrintStudentScoreClassComboBox.getItems().clear();
        ArrayList<String> chooselist = new ArrayList<>();
        Score score;
        String teacherName = DataField.LoginedUser.Name;
        for(int i = 0; i< scoreData.size(); i++){
            score = scoreData.get(i);
            if(score.CourseName.equals(choosedCourse) && score.TeacherName.equals(teacherName)){//如果课名和老师名一致
                if(StringNotExistInArraylist(score.StudentGrade,chooselist)){//如果没有添加过
                    TeacherInputOrPrintStudentScoreGradeComboBox.getItems().add(score.StudentGrade);//加入选项
                    chooselist.add(score.StudentGrade);//加入Arraylist中
                }//if
            }//if
        }//for
    }//清空后面的选项，记录当前选项，根据老师名、课名从ScoreData查找参与本课程的年级

    public void TeacherInputOrPrintStudentScoreGradeComboBoxOnAction(){//清空后面的选项，记录当前选项，根据老师名、课名、年级从ScoreData查找参与本课程的年级
        choosedGrade = (String) TeacherInputOrPrintStudentScoreGradeComboBox.getValue();
        TeacherInputOrPrintStudentScoreMajorComboBox.getItems().clear();
        TeacherInputOrPrintStudentScoreClassComboBox.getItems().clear();
        ArrayList<String> chooselist = new ArrayList<>();
        Score score;
        String teacherName = DataField.LoginedUser.Name;
        //为下一个选择框寻找选项
        for(int i = 0; i< scoreData.size(); i++){
            score = scoreData.get(i);
            if(score.CourseName.equals(choosedCourse) && score.TeacherName.equals(teacherName)
                    && score.StudentGrade.equals(choosedGrade)){//如果课名、老师名、年级一致
                if(StringNotExistInArraylist(score.StudentMajor,chooselist)){//如果该选项没有添加过
                    TeacherInputOrPrintStudentScoreMajorComboBox.getItems().add(score.StudentMajor);//加入选项
                    chooselist.add(score.StudentMajor);//加入Arraylist中
                }//if
            }//if
        }//for
    }//清空后面的选项，记录当前选项，根据老师名、课名、年级从ScoreData查找参与本课程的专业

    public void TeacherInputOrPrintStudentScoreMajorComboBoxOnAction(){//清空后面的选项，记录当前选项，根据老师名、课名、年级、专业从ScoreData查找参与本课程的班级
        choosedMajor = (String) TeacherInputOrPrintStudentScoreMajorComboBox.getValue();
        TeacherInputOrPrintStudentScoreClassComboBox.getItems().clear();
        ArrayList<String> chooselist = new ArrayList<>();
        Score score;
        String teacherName = DataField.LoginedUser.Name;
        //为下一个选择框寻找选项
        for(int i = 0; i< scoreData.size(); i++){
            score = scoreData.get(i);
            if(score.CourseName.equals(choosedCourse) && score.TeacherName.equals(teacherName)
                    && score.StudentGrade.equals(choosedGrade)
                    && score.StudentMajor.equals(choosedMajor)){//如果课名、老师名、年级、专业一致
                if(StringNotExistInArraylist(score.StudentClass,chooselist)){//如果该选项没有添加过
                    TeacherInputOrPrintStudentScoreClassComboBox.getItems().add(score.StudentClass);//加入选项
                    chooselist.add(score.StudentClass);//加入Arraylist中
                }//if
            }//if
        }//for
    }//清空后面的选项，记录当前选项，根据老师名、课名、年级、专业从ScoreData查找参与本课程的班级

    public void SaveComboBoxValue(){
        choosedCourse = (String)TeacherInputOrPrintStudentScoreCourseComboBox.getValue();
        choosedGrade = (String)TeacherInputOrPrintStudentScoreGradeComboBox.getValue();
        choosedMajor = (String)TeacherInputOrPrintStudentScoreMajorComboBox.getValue();
        choosedClass = (String)TeacherInputOrPrintStudentScoreClassComboBox.getValue();
        System.out.println(choosedCourse+"  "+choosedGrade+"  "+choosedMajor+"  "+choosedClass);
    }

    public void TeacherInputOrPrintStudentScore(){
        //步骤：
        //1.在scorelist中查找课名、年级、专业、班级对应的学生score结点并删除这些结点
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("2")){//如果是教师
            TeacherInputOrPrintStudentScorePane.setVisible(true);//可见
            TeacherInputOrPrintStudentScorePane.setDisable(false);//可用
            TeacherInputOrPrintStudentScoreCourseComboBoxPrepared();//为第一个选项框准备选项
            TeacherInputOrPrintStudentScoreTipText.setText("");
            System.out.println("教师录入/打印学生成绩");
        }//if
        //如果不是教师，什么都不能做
    }//教师根据课名、班级、专业、班级录入学生成绩

    //1.录入学生成绩
    public void openTeacherInputWindows() throws Exception{
        Stage stage = new Stage();
        BorderPane root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmil/linwei/comprehensive/FXML/TeacherInputWindows.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.show();
    }//打开录入成绩页面

    public void TeacherInputScore(){
        if(TeacherInputOrPrintStudentScoreCourseComboBox.getValue() == null||
                TeacherInputOrPrintStudentScoreGradeComboBox.getValue() == null||
                TeacherInputOrPrintStudentScoreMajorComboBox.getValue() == null||
                TeacherInputOrPrintStudentScoreClassComboBox.getValue() == null){
            TeacherInputOrPrintStudentScoreTipText.setText("请填写选项");
            return;
        }
        //如果全部选项卡都已经填写
        CloseTeacherMainWindows();//保存舞台和控制器，并关闭本舞台
        try{
            openTeacherInputWindows();//打开录入学生成绩面板
        }
        catch (Exception e){
            System.out.println("打开TeacherInput窗口失败");
            System.out.println(e);
        }
    }//点击录入/修改学生成绩按钮
    //2.打印学生成绩
    public void openTeacherReportWindows() throws Exception{
        Stage stage = new Stage();
        BorderPane root = FXMLLoader.load(getClass().getResource("/cn/edu/scau/cmil/linwei/comprehensive/FXML/TeacherReportWindows.fxml"));
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.initStyle(StageStyle.TRANSPARENT);
        stage.show();
    }//打开成绩报告页面

    public void TeacherPrintScore(){
        if(TeacherInputOrPrintStudentScoreCourseComboBox.getValue() == null||
                TeacherInputOrPrintStudentScoreGradeComboBox.getValue() == null||
                TeacherInputOrPrintStudentScoreMajorComboBox.getValue() == null||
                TeacherInputOrPrintStudentScoreClassComboBox.getValue() == null){
            TeacherInputOrPrintStudentScoreTipText.setText("请填写选项");
            return;
        }
        CloseTeacherMainWindows();//保存舞台和控制器，并关闭本舞台
        try{
            openTeacherReportWindows();//打开学生成绩面板
        }
        catch (Exception e){
            System.out.println("打开TeacherReport窗口失败");
        }
    }//打印学生成绩，调用上面的printStudentScore()

    /*【下面是管理员操作对应的实现】*/
    //添加课程
    public void AdminAddCourseAction(){
        //检查是否存在，若不存在，添加入courselist中，然后写入一遍courselist
        String course = AdminAddCourseOrMajorOrGradeOrWhitelistTextField.getText();
        if(course.equals("")){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("输入为空，请重新输入");
            return;
        }
        String tmp;
        int count = 0;
        for(int i = 0; i<DataField.courseList.size(); i++){
            tmp = DataField.courseList.get(i);
            if(tmp.equals(course)){
                count++;
            }
        }
        if(count>0){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("此课程已存在");
        }
        else{
            DataField.courseList.add(course);
            DataField.courseList.sort(new Comparator<String>() {
                Collator collator = Collator.getInstance();
                @Override
                public int compare(String o1, String o2) {
                    return collator.compare(o1,o2);
                }
            });
            try{
                DataIO.CourseWrite();
            }
            catch (IOException e){ System.out.println("Course.txt写入失败"+e); }
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("课程  "+course+"  添加成功");
        }
    }//添加课程Action

    public void AdminAddCourse(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setVisible(true);//可见
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setDisable(false);//可用
            AdminAddCourseOrMajorOrGradeOrWhitelistText.setText("课程名：");
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("");
            AdminAddCourseOrMajorOrGradeOrWhitelistTextField.setPromptText("请输入需要添加的课程名");
            AdminAddCourseOrMajorOrGradeOrWhitelistButton.setOnAction(e->AdminAddCourseAction());
            System.out.println("管理员添加课程");
        }
        //如果不是管理员，什么都不能做
    }//添加课程

    //删除课程
    public void AdminDelCourseComboBoxPrepared(){
        AdminDelCourseComboBox.getItems().clear();
        AdminDelCourseComboBox.getItems().addAll(DataField.courseList);
    }//为选项框准备内容

    public void AdminDelCourseFromcourselist(String coursename){
        String tmp;
        for(int i = 0;i<DataField.courseList.size();i++){
            tmp = DataField.courseList.get(i);
            if(tmp.equals(coursename)){
                DataField.courseList.remove(i);
                break;//可以停止查找
            }
        }
        System.out.println("课程信息：");
        for(String s:DataField.courseList){
            System.out.println(s);
        }

    }//从courselist中删除课

    public void AdminDelCourseFromteacherdata(String coursename){
        Teacher teacher;
        String tmp;
        for(int i = 0;i<DataField.teacherData.size();i++){
            teacher = DataField.teacherData.get(i);
            for(int j = 0;j<teacher.teachCourse.size();j++){
                tmp = teacher.teachCourse.get(j);
                if(tmp.equals(coursename)){
                    teacher.teachCourse.remove(j);//不能停止查找，可以有多个老师上这门课
                    j-=1;
                    i-=1;
                }
            }

        }
        System.out.println("教师信息：");
        for(int i = 0;i<DataField.teacherData.size();i++){//遍历教师数据
            System.out.println(DataField.teacherData.get(i).ID);//获取第I个教师的ID
            System.out.println(DataField.teacherData.get(i).Name);//获取第I个教师的姓名
            for(String s:DataField.teacherData.get(i).teachCourse){//获取第I个教师的教学科目
                System.out.println("该教师教授的课程："+s);
            }
        }
    }//从teacherdata中删除课

    public void AdminDelCourseFromscoredata(String coursename){
        Score score;
        String tmp;
        for(int i = 0;i<DataField.scoreData.size();i++){
            score = DataField.scoreData.get(i);
            tmp = score.CourseName;
            if(tmp.equals(coursename)){
                DataField.scoreData.remove(i);//不能停止查找，可以有多个学生上这门课
                i-=1;
            }
        }
        System.out.println("Score信息：");
        for(int i = 0;i<DataField.scoreData.size();i++){
            score = DataField.scoreData.get(i);
            System.out.println(score.StudentID);
            System.out.println(score.StudentName);
            System.out.println(score.StudentGrade);
            System.out.println(score.StudentMajor);
            System.out.println(score.StudentClass);
            System.out.println(score.TeacherName);
            System.out.println(score.CourseName);
            System.out.println(score.Attend);
            System.out.println(score.Exam);
            System.out.println(score.Work);
            System.out.println(score.FinalExam);
            System.out.println(score.TotalScore);
        }

    }//从scoredata中删除课

    public void AdminDelCourseAction() throws IOException {
        //没有学生上课时，从courselist和teacherdata的teachcourse中删除即可
        //有学生上课时，从scoredata，teacherdata的teachcourse，courseList中删除
        String coursename = (String)AdminDelCourseComboBox.getValue();
        Score score;
        for(int i = 0;i<DataField.scoreData.size();i++){
            score = DataField.scoreData.get(i);
            if(score.CourseName.equals(coursename)){
                //如果有学生上这门课，弹出Tip窗口
                openTipWindows("该课程有学生上课，仍要删除？\n如果删除会导致课程信息从学生及教师列表消失","删除","返回");
                System.out.println("openTipWindows执行完毕");
                if(TipChoose == true){
                    AdminDelCourseFromscoredata(coursename);//从scoreddata中移除数据
                    break;//break for
                }
                else{
                    AdminDelCourseTipText.setText("取消删除");
                    return;
                }
            }
        }
        //无论有没有学生上这门课，都要从courselist和teacherdata中移除数据
        AdminDelCourseFromcourselist(coursename);
        AdminDelCourseFromteacherdata(coursename);
        AdminDelCourseTipText.setText("删除成功");
        AdminDelCourseComboBox.getItems().clear();
        AdminDelCourseComboBoxPrepared();
        if(TipChoose == true){
            DataIO.ScoreWrite();
        }
        DataIO.CourseWrite();
        DataIO.TeacherWrite();
    }//删除课程Action

    public void AdminDelCourse(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminDelCoursePane.setVisible(true);//可见
            AdminDelCoursePane.setDisable(false);//可用
            AdminDelCourseText.setText("课程名：");
            AdminDelCourseTipText.setText("");
            AdminDelCourseComboBox.setPromptText("选择删除的课程");
            AdminDelCourseComboBoxPrepared();
            AdminDelCourseButton.setOnAction(e-> {
                try {
                    AdminDelCourseAction();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            });
            AdminDelCourseButton.setText("删除");
            System.out.println("管理员删除课程");
        }
        //如果不是管理员，什么都不能做
    }//删除课程

    //添加年级
    public void SortGradeList(){//对Gradelist进行排序，小的数在前面，大的数在后面
        DataField.gradeList.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int i = Integer.parseInt(o1)>Integer.parseInt(o2)?1:-1;
                return i;
            }
        });
    }

    public void AdminAddGradeAction(){
        //检查是否存在，若不存在，添加入gradelist中，然后写入一遍gradelist
        String grade = AdminAddCourseOrMajorOrGradeOrWhitelistTextField.getText();
        if(grade.equals("")){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("输入为空，请重新输入");
            return;
        }
        String tmp;
        int count = 0;
        for(int i = 0; i<DataField.gradeList.size(); i++){
            tmp = DataField.gradeList.get(i);
            if(tmp.equals(grade)){
                count++;
            }
        }
        if(count>0){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("此年级已存在");
        }
        else{
            DataField.gradeList.add(grade);
            SortGradeList();//对年级进行排序
            try{
                DataIO.GradeWrite();
            }
            catch (IOException e){ System.out.println("Grade.txt写入失败"+e); }
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("年级  "+grade+"  添加成功");
        }
    }//添加年级Action

    public void AdminAddGrade(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setVisible(true);//可见
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setDisable(false);//可用
            AdminAddCourseOrMajorOrGradeOrWhitelistText.setText("年级：");
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("");
            AdminAddCourseOrMajorOrGradeOrWhitelistTextField.setPromptText("请输入需要添加的年级");
            AdminAddCourseOrMajorOrGradeOrWhitelistButton.setOnAction(e->AdminAddGradeAction());
            System.out.println("管理员添加年级");
        }
        //如果不是管理员，什么都不能做
    }//添加年级

    //删除年级
    public void AdminDelGradeComboBoxPrepared(){
        AdminDelCourseComboBox.getItems().clear();
        AdminDelCourseComboBox.getItems().addAll(DataField.gradeList);
    }

    public void AdminDelGradeFromGradelist(String grade) throws IOException {
        String tmp;
        for(int i = 0;i<DataField.gradeList.size();i++){
            tmp = DataField.gradeList.get(i);
            if(tmp.equals(grade)){
                DataField.gradeList.remove(i);
                break;//可以停止查找
            }
        }

        DataIO.GradeWrite();

        System.out.println("年级信息：");
        for(String s:DataField.gradeList){
            System.out.println(s);
        }

    }

    public void AdminDelGradeAction() throws IOException {
        //关于年级
        // 1.空年级,直接AdminDelGradeFromGradelist
        // 2.这个年级有班级但没有学生，删除班级，删除年级
        // 3.这个年级有班级而且有学生，删除班级，删除年级，注销学生【这个年级有学生，这个年级就一定有班级，因为学生存在于班级中】
        // 具体过程类似删除专业
        String grade = (String)AdminDelCourseComboBox.getValue();
        //首先遍历studentdata里面的年级专业班号，看一下里面有没有学生是这个专业的
        Student student;
        StudentClass studentClass;
        boolean haveStudent = false;
        ArrayList<String> delStudentIDList = new ArrayList<>();//用于存储需要删除的该专业学生的id
        int i =0;
        int delClassNum = 0;
        //查找这个年级是否有学生
        for(;i<DataField.studentData.size();i++){//i从0开始
            student = DataField.studentData.get(i);
            studentClass = student.myclass;//获取这个学生的年级专业班级
            if(studentClass.StudentGrade.equals(grade)){
                haveStudent = true;//这个专业里有学生
                break;//break for
            }
        }
        boolean haveClass = false;
        int j;
        for(j = 0;j<DataField.classList.size();j++){
            studentClass = DataField.classList.get(j);
            if(studentClass.StudentGrade.equals(grade)){
                haveClass = true;//这个专业有班级
                break;
            }
        }

        if(haveStudent && haveClass){//如果有学生在这个年级里，弹出Tip窗口
            openTipWindows("该年级里有学生和班级，仍要删除？","删除","返回");
            if(TipChoose == true){
                for(;i<DataField.studentData.size();i++){//从之前的下标继续查找所有这个年级的学生的id，防止重复查找
                    //在之前的i已经发现第一个匹配的学生，从这个i开始查找，不会漏掉学生
                    student = DataField.studentData.get(i);
                    studentClass = student.myclass;//获取这个学生的年级专业班级
                    if(studentClass.StudentGrade.equals(grade)){
                        delStudentIDList.add(student.ID);//把这个学生的ID放入数组中
                    }
                }
                for(String tmp:delStudentIDList){//调用帐号注销方法， 注销所有学生，学生数为数组size
                    AdminCalcelUserFromUserdata(tmp);//从User中删除
                    AdminCancelStudentExpectUserdata(tmp);//从scoredata和studentdata中删除
                }
                for(int z = 0;z<DataField.classList.size();z++){//移除所有这个年级的班级
                    studentClass = DataField.classList.get(z);
                    if(studentClass.StudentGrade.equals(grade)){
                        DataField.classList.remove(z);
                        z-=1;//一定要j--，否则可能会跳过一些结点
                        delClassNum++;
                    }
                }
                DataIO.ClassWrite();
            }
            else{//不删除，直接return
                AdminDelCourseTipText.setText("取消删除");
                return;
            }
        }//if have Student

        else if(haveClass){//这个年级有空班级，删除空班级【不会出现有学生没班级的情况，有学生就一定在这个班级里】
            openTipWindows("该专业里有空班级，仍要删除？","删除","返回");
            if(TipChoose == true){
                for(j = 0;j<DataField.classList.size();j++){
                    studentClass = DataField.classList.get(j);
                    if(studentClass.StudentGrade.equals(grade)){
                        DataField.classList.remove(j);
                        j-=1;//一定要j--，否则可能会跳过一些结点
                        delClassNum++;
                    }
                }
                DataIO.ClassWrite();
            }
            else{//不删除，直接return
                AdminDelCourseTipText.setText("取消删除");
                return;
            }
        }
        //如果没有return，证明
        //1.有学生和班级在这个年级里，选择仍然删除
        //2.有空班级在这个年级里，选择仍然删除
        //3.没有学生和班级在这个专业里，是一个空年级
        AdminDelGradeFromGradelist(grade);//从gradelist中删除这个专业
        AdminDelCourseTipText.setText("删除成功，共删除"+delStudentIDList.size()+"位学生，"+delClassNum+"个班级");
        AdminDelCourseComboBox.getItems().clear();
        AdminDelGradeComboBoxPrepared();
    }//删除年级Action

    public void AdminDelGrade(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminDelCoursePane.setVisible(true);//可见
            AdminDelCoursePane.setDisable(false);//可用
            AdminDelCourseText.setText("年级名：");
            AdminDelCourseTipText.setText("");
            AdminDelCourseComboBox.setPromptText("选择删除的年级");
            AdminDelGradeComboBoxPrepared();
            AdminDelCourseButton.setOnAction(e-> {
                try {
                    AdminDelGradeAction();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            });
            AdminDelCourseButton.setText("删除");
            System.out.println("管理员删除年级");
        }
        //如果不是管理员，什么都不能做
    }//删除年级
    //添加专业
    public void AdminAddMajorAction(){
        //检查是否存在，若不存在，添加入majorlist中，然后写入一遍majorlist
        String major = AdminAddCourseOrMajorOrGradeOrWhitelistTextField.getText();
        if(major.equals("")){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("输入为空，请重新输入");
            return;
        }
        String tmp;
        int count = 0;
        for(int i = 0; i<DataField.majorList.size(); i++){
            tmp = DataField.majorList.get(i);
            if(tmp.equals(major)){
                count++;
            }
        }
        if(count>0){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("此专业已存在");
        }
        else{
            DataField.majorList.add(major);
            DataField.majorList.sort(new Comparator<String>() {
                Collator collator = Collator.getInstance();
                @Override
                public int compare(String o1, String o2) {
                    return collator.compare(o1,o2);
                }
            });
            try{
                DataIO.MajorWrite();
            }
            catch (IOException e){ System.out.println("Major.txt写入失败"+e); }
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("专业  "+major+"  添加成功");
        }
    }//添加专业Action

    public void AdminAddMajor(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setVisible(true);//可见
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setDisable(false);//可用
            AdminAddCourseOrMajorOrGradeOrWhitelistText.setText("专业：");
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("");
            AdminAddCourseOrMajorOrGradeOrWhitelistTextField.setPromptText("请输入需要添加的专业");
            AdminAddCourseOrMajorOrGradeOrWhitelistButton.setOnAction(e->AdminAddMajorAction());
            System.out.println("管理员添加专业");
        }
        //如果不是管理员，什么都不能做
    }//添加专业
    //删除专业
    public void AdminDelMajorComboBoxPrepared(){
        AdminDelCourseComboBox.getItems().clear();
        AdminDelCourseComboBox.getItems().addAll(DataField.majorList);
    }

    public void AdminDelMajorFromMajorlist(String major) throws IOException {
        String tmp;
        for(int i = 0;i<DataField.majorList.size();i++){
            tmp = DataField.majorList.get(i);
            if(tmp.equals(major)){
                DataField.majorList.remove(i);
                break;//可以停止查找
            }
        }

        DataIO.MajorWrite();

        System.out.println("专业信息：");
        for(String s:DataField.majorList){
            System.out.println(s);
        }


    }//从majorlist中删除专业

    public void AdminDelMajorAction() throws IOException {
        //如果这个专业里有学生，删除这些专业的学生、班级，注销这些学生用户，删除这些班级，如果没有学生，直接从majorlist中删除即可
        //这个专业的学生一定在这个专业的班级里，把classlist里面的数据也删除即可
        String major = (String)AdminDelCourseComboBox.getValue();
        //首先遍历studentdata里面的年级专业班号，看一下里面有没有学生是这个专业的
        Student student;
        StudentClass studentClass;
        boolean haveStudent = false;
        ArrayList<String> delStudentIDList = new ArrayList<>();//用于存储需要删除的该专业学生的id
        int i =0;
        int delClassNum = 0;
        //查找这个专业是否有学生
        for(;i<DataField.studentData.size();i++){//i从0开始
            student = DataField.studentData.get(i);
            studentClass = student.myclass;//获取这个学生的年级专业班级
            if(studentClass.StudentMajor.equals(major)){
                haveStudent = true;//这个专业里有学生
                break;//break for
            }
        }
        boolean haveClass = false;
        int j;
        for(j = 0;j<DataField.classList.size();j++){
            studentClass = DataField.classList.get(j);
            if(studentClass.StudentMajor.equals(major)){
                haveClass = true;//这个专业有班级
                break;
            }
        }

        if(haveStudent && haveClass){//如果有学生在这个专业里，弹出Tip窗口
            openTipWindows("该专业里有学生和班级，仍要删除？","删除","返回");
            if(TipChoose == true){
                for(;i<DataField.studentData.size();i++){//从之前的下标继续查找所有这个专业的学生的id，防止重复查找
                    //在之前的i已经发现第一个匹配的学生，从这个i开始查找，不会漏掉学生
                    student = DataField.studentData.get(i);
                    studentClass = student.myclass;//获取这个学生的年级专业班级
                    if(studentClass.StudentMajor.equals(major)){
                        delStudentIDList.add(student.ID);//把这个学生的ID放入数组中
                    }
                }
                for(String tmp:delStudentIDList){//调用帐号注销方法， 注销所有学生，学生数为数组size+1
                    AdminCalcelUserFromUserdata(tmp);//从User中删除
                    AdminCancelStudentExpectUserdata(tmp);//从scoredata和studentdata中删除
                }
                for(int z = 0;z<DataField.classList.size();z++){
                    studentClass = DataField.classList.get(z);
                    if(studentClass.StudentMajor.equals(major)){
                        DataField.classList.remove(z);
                        z-=1;//一定要j--，否则可能会跳过一些结点
                        delClassNum++;
                    }
                }
                DataIO.ClassWrite();
            }
            else{//不删除，直接return
                AdminDelCourseTipText.setText("取消删除");
                return;
            }
        }//if have Student

        else if(haveClass){//这个专业有空班级，删除空班级【不会出现有学生没班级的情况，有学生就一定在这个班级里】
            openTipWindows("该专业里有空班级，仍要删除？","删除","返回");
            if(TipChoose == true){
                for(j = 0;j<DataField.classList.size();j++){
                    studentClass = DataField.classList.get(j);
                    if(studentClass.StudentMajor.equals(major)){
                        DataField.classList.remove(j);
                        j-=1;//一定要j--，否则可能会跳过一些结点
                        delClassNum++;
                    }
                }
                DataIO.ClassWrite();
            }
            else{//不删除，直接return
                AdminDelCourseTipText.setText("取消删除");
                return;
            }
        }
        //如果没有return，证明
        //1.有学生和班级在这个专业里，选择仍然删除
        //2.有空班级在这个专业里，选择仍然删除
        //3.没有学生和班级在这个专业里，是一个空专业
        AdminDelMajorFromMajorlist(major);//从majorlist中删除这个专业
        AdminDelCourseTipText.setText("删除成功，共删除"+delStudentIDList.size()+"位学生，"+delClassNum+"个班级");
        AdminDelCourseComboBox.getItems().clear();
        AdminDelMajorComboBoxPrepared();
    }//删除专业Action

    public void AdminDelMajor(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminDelCoursePane.setVisible(true);//可见
            AdminDelCoursePane.setDisable(false);//可用
            AdminDelCourseText.setText("专业名：");
            AdminDelCourseTipText.setText("");
            AdminDelCourseComboBox.setPromptText("选择删除的专业");
            AdminDelMajorComboBoxPrepared();
            AdminDelCourseButton.setOnAction(e-> {
                try {
                    AdminDelMajorAction();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            });
            AdminDelCourseButton.setText("删除");
            System.out.println("管理员删除专业");
        }
        //如果不是管理员，什么都不能做
    }//删除专业

    //添加班级
    public void AdminAddClassGradeComboBoxPrepare(){
        AdminAddClassGradeComboBox.getItems().clear();
        AdminAddClassMajorComboBox.getItems().clear();
        AdminAddClassNumComboBox.getItems().clear();
        //把所有年级添加为AdminAddClassGradeComboBox选项
        AdminAddClassGradeComboBox.getItems().addAll(DataField.gradeList);
    }

    public void AdminAddClassGradeComboBoxOnAction(){
        AdminAddClassMajorComboBox.getItems().clear();
        AdminAddClassNumComboBox.getItems().clear();
        //把所有专业添加为AdminAddClassMajorComboBox选项
        AdminAddClassMajorComboBox.getItems().addAll(DataField.majorList);
    }

    public void AdminAddClassMajorComboBoxOnAction(){
        AdminAddClassNumComboBox.getItems().clear();
        //把所有班级数添加为AdminAddClassMajorComboBox选项
        AdminAddClassNumComboBox.getItems().addAll("1","2","3","4","5","6","7","8","9","10");
    }

    public void AdminAddClassAction(){
        //检查是否存在，若不存在，添加入classlist中，然后写入一遍classlist
        String grade = (String)AdminAddClassGradeComboBox.getValue();
        String major =  (String)AdminAddClassMajorComboBox.getValue();
        String classnum =  (String)AdminAddClassNumComboBox.getValue();

        if(AdminAddClassGradeComboBox.getValue()==null ||
                AdminAddClassMajorComboBox.getValue()==null ||
                AdminAddClassNumComboBox.getValue()==null){//有一个为空都不行
            AdminAddClassTipText.setText("请填入所有信息");
            return;
        }
        StudentClass tmp;
        int count = 0;
        for(int i = 0; i<DataField.classList.size(); i++){
            tmp = DataField.classList.get(i);
            if(tmp.StudentGrade.equals(grade) && tmp.StudentMajor.equals(major) && tmp.StudentClass.equals(classnum)){
                count++;
            }
        }
        if(count>0){
            AdminAddClassTipText.setText("此班级已存在");
        }
        else{
            DataField.classList.add(new StudentClass(grade,major,classnum));
            DataField.classList.sort(new Comparator<StudentClass>() {
                Collator collator = Collator.getInstance();
                @Override
                //排序方式：年级>专业>班级
                public int compare(StudentClass o1, StudentClass o2) {
                    if(!o1.StudentGrade.equals(o2.StudentGrade)){//如果年级不想等，返回比较结果
                        return o1.StudentGrade.compareTo(o2.StudentGrade);
                    }
                    else{//如果年级相等，比较专业
                        if(!o1.StudentMajor.equals(o2.StudentMajor)){//如果专业不相等，返回比较结果
                            return collator.compare(o1.StudentMajor,o2.StudentMajor);//需要用collator来比较中文字符串。专业是中文名
                        }
                        else{//如果年级专业都相等
                            return o1.StudentClass.compareTo(o2.StudentClass);//返回班级数的比较结果
                        }
                    }
                }
            });

            try{
                DataIO.ClassWrite();
            }
            catch (IOException e){ System.out.println("class.txt写入失败"+e); }

            AdminAddClassTipText.setText(grade+"级"+major+"专业"+classnum+"班  添加成功");
        }
    }//添加班级Action

    public void AdminAddClass(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminAddClassPane.setVisible(true);//可见
            AdminAddClassPane.setDisable(false);//可用
            AdminAddClassTipText.setText("");
            AdminAddClassButton.setText("确定");
            AdminAddClassButton.setOnAction(e->AdminAddClassAction());
            AdminAddClassGradeComboBox.setOnAction(e->AdminAddClassGradeComboBoxOnAction());
            AdminAddClassMajorComboBox.setOnAction(e->AdminAddClassMajorComboBoxOnAction());
            AdminAddClassGradeComboBoxPrepare();
            System.out.println("管理员添加班级");
        }
        //如果不是管理员，什么都不能做
    }//添加班级

    //删除班级
    public void AdminDelClassFromClasslist(String grade,String major,String classnum) throws IOException {
        //从classlist中删除这个班级
        //System.out.println("AdminDelClassFromClasslist："+grade+major+classnum);
        StudentClass studentClass;
        for(int i =0;i<DataField.classList.size();i++){
            studentClass = DataField.classList.get(i);
            if(studentClass.StudentGrade.equals(grade) && studentClass.StudentMajor.equals(major) &&
                studentClass.StudentClass.equals(classnum)){
                //如果找到这个班
                //System.out.println("删除"+grade+major+classnum);
                DataField.classList.remove(i);
                break;
            }
        }
        DataIO.ClassWrite();
    }

    public void AdminDelClassMajorComboBoxOnAction(){
        AdminAddClassNumComboBox.getItems().clear();
        //把所有班级数添加为AdminAddClassMajorComboBox选项
        String grade = (String)AdminAddClassGradeComboBox.getValue();
        String major =  (String)AdminAddClassMajorComboBox.getValue();
        StudentClass studentClass;
        for(int i =0;i<DataField.classList.size();i++){
            studentClass = DataField.classList.get(i);
            if(studentClass.StudentGrade.equals(grade) && studentClass.StudentMajor.equals(major)){
                //如果年级专业都相等，把班号加进选项里
                AdminAddClassNumComboBox.getItems().add(studentClass.StudentClass);
            }
        }

    }

    public void AdminDelClassAction() throws IOException {
        //检查是否存在，若不存在，添加入classlist中，然后写入一遍classlist
        String grade = (String)AdminAddClassGradeComboBox.getValue();
        String major =  (String)AdminAddClassMajorComboBox.getValue();
        String classnum =  (String)AdminAddClassNumComboBox.getValue();
        //关于班级
        // 1.空班级,直接AdminDelClassFromClasslist
        // 2.这个班级有学生，删除班级AdminDelClassFromClasslist，注销学生
        //首先遍历studentdata里面的年级专业班号，看一下里面有没有学生是这个班级的
        Student student;
        StudentClass studentClass;
        boolean haveStudent = false;
        ArrayList<String> delStudentIDList = new ArrayList<>();//用于存储需要删除的该专业学生的id
        int i =0;
        //查找这个班级是否有学生
        for(;i<DataField.studentData.size();i++){//i从0开始
            student = DataField.studentData.get(i);
            studentClass = student.myclass;//获取这个学生的年级专业班级
            if(studentClass.StudentGrade.equals(grade) && studentClass.StudentMajor.equals(major) &&
                studentClass.StudentClass.equals(classnum)){//年级、专业、班级都相等
                haveStudent = true;//这个专业里有学生
                break;//break for
            }
        }
        if(haveStudent){//如果有学生在这个班级里，弹出Tip窗口
            openTipWindows("该班级里有学生，仍要删除？","删除","返回");
            if(TipChoose == true){
                for(;i<DataField.studentData.size();i++){//从之前的下标继续查找所有这个班级的学生的id，防止重复查找
                    //在之前的i已经发现第一个匹配的学生，从这个i开始查找，不会漏掉学生
                    student = DataField.studentData.get(i);
                    studentClass = student.myclass;//获取这个学生的年级专业班级
                    if(studentClass.StudentGrade.equals(grade) && studentClass.StudentMajor.equals(major) &&
                            studentClass.StudentClass.equals(classnum)){
                        delStudentIDList.add(student.ID);//把这个学生的ID放入数组中
                    }
                }
                for(String tmp:delStudentIDList){//调用帐号注销方法， 注销所有学生，学生数为数组size
                    AdminCalcelUserFromUserdata(tmp);//从User中删除
                    AdminCancelStudentExpectUserdata(tmp);//从scoredata和studentdata中删除
                }
            }
            else{//不删除，直接return
                AdminAddClassTipText.setText("取消删除");
                return;
            }
        }//if have Student
        //如果没有return，证明
        //1.有学生在这个班级里，选择仍然删除
        //3.没有学生在这个班级里，是一个空班级
        AdminDelClassFromClasslist(grade,major,classnum);//从classlist中删除这个专业
        AdminAddClassTipText.setText("成功删除"+grade+"级"+major+"专业"+classnum+"班，并删除"+delStudentIDList.size()+"位学生，");
        AdminDelClassMajorComboBoxOnAction();
    }//删除班级Action

    public void AdminDelClass(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminAddClassPane.setVisible(true);//可见
            AdminAddClassPane.setDisable(false);//可用
            AdminAddClassTipText.setText("");
            AdminAddClassButton.setText("删除");
            AdminAddClassButton.setOnAction(e-> {
                try {
                    AdminDelClassAction();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            });
            AdminAddClassGradeComboBox.setOnAction(e->AdminAddClassGradeComboBoxOnAction());
            AdminAddClassMajorComboBox.setOnAction(e->AdminDelClassMajorComboBoxOnAction());
            AdminAddClassGradeComboBoxPrepare();
            System.out.println("管理员删除班级");
        }
        //如果不是管理员，什么都不能做
    }//删除班级

    //查看用户信息
    public final ObservableList<UserData> UserdataObservableList = FXCollections.observableArrayList();

    public void InitAdminWatchUserInformationTableView(){
        //设置六列，将数据关联到表中的列
        IDTableColumn.setCellValueFactory(new PropertyValueFactory<>("ID"));//第一列中的数据关联UserData中的StudentID
        PWTableColumn.setCellValueFactory(new PropertyValueFactory<>("PW"));//第二列中的数据关联SUserData中的PW
        NameTableColumn.setCellValueFactory(new PropertyValueFactory<>("Name"));
        UserKindTableColumn.setCellValueFactory(new PropertyValueFactory<>("UserKind"));
        InitQuestionTableColumn.setCellValueFactory(new PropertyValueFactory<>("InitQuestion"));
        InitAnswerTableColumn.setCellValueFactory(new PropertyValueFactory<>("InitAnswer"));
        //AdminWatchUserInformationTableView.getItems().clear();
        AdminWatchUserInformationTableView.setItems(UserdataObservableList);//数据关联到tableView
    }//初始化表格

    public void SearchforMainTable(){
        //把User的所有信息都add进data里
        UserdataObservableList.clear();
        User user;
        for(int i = 0; i<DataField.userData.size(); i++){
            user = DataField.userData.get(i);
            UserData userData = new UserData(user.ID,user.PW,user.Name,user.UserKind,user.InitQuestion,user.InitAnswer);
            UserdataObservableList.add(userData);//把学生信息添加进表格关联的list中
        }
    }//为主表格搜索数据

    public void AdminWatchUserInformation(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminWatchUserInformationPane.setVisible(true);//可见
            AdminWatchUserInformationPane.setDisable(false);//可用
            AdminWatchUserInformationTipText.setText("共有"+DataField.userData.size()+"名用户，单击用户查看用户详细信息");
            AdminWatchUserInformationDetailText.setText("");
            InitAdminWatchUserInformationTableView();
            SearchforMainTable();
            System.out.println("管理员查看用户信息");
        }
        //如果不是管理员，什么都不能做
    }//查看用户信息

    public void AdminWatchUserInformationTableViewMouseClicked(){
        int i = AdminWatchUserInformationTableView.getSelectionModel().getFocusedIndex();
        UserData userData = UserdataObservableList.get(i);
        String detailInfo = new String();
        if(userData.getUserKind().equals("学生")){//如果是学生
            String ID = userData.getID();
            String grade = new String();
            String major = new String();
            String classnum = new String();
            Score score;
            ArrayList<String> courselist = new ArrayList<>();
            //在Score找到所有课程，并且看到他是哪个班的
            for(i = 0;i<DataField.scoreData.size();i++){
                score = DataField.scoreData.get(i);
                if(score.StudentID.equals(ID)){//找到一门课程
                    grade = score.StudentGrade;
                    major = score.StudentMajor;
                    classnum = score.StudentClass;
                    courselist.add(score.CourseName);
                }
            }
            detailInfo = "班级：\n"+grade+"级"+major+"专业"+classnum+"班\n课程：\n";
            for(String s:courselist){
                detailInfo+=s+"\n";
            }
        }
        else if(userData.getUserKind().equals("老师")){
            detailInfo = "开设课程：\n";
            String ID = userData.getID();
            Teacher teacher;
            for(i =0;i<DataField.teacherData.size();i++){
                teacher = DataField.teacherData.get(i);
                if(teacher.ID.equals(ID)){//找到这个老师，遍历他的课表
                    for(String s:teacher.teachCourse){
                        detailInfo+=s+"\n";
                    }
                    break;
                }
            }
        }
        else if(userData.getUserKind().equals("管理员")){
            detailInfo = "管理员深不可测\n无法窥得信息";
        }
        AdminWatchUserInformationDetailText.setText(detailInfo);
    }//显示选中用户的详细信息

    //帐号注销
    public void AdminCalcelUserFromUserdata(String id) throws IOException {
        User user;
        for (int i = 0; i < DataField.userData.size(); i++) {
            user = DataField.userData.get(i);
            if (user.ID.equals(id)) {//找到这个用户
                System.out.println("找到用户");
                DataField.userData.remove(i);//在User中删除该用户
                for (User s : DataField.userData) {
                    System.out.println("帐号信息：" + s.ID + "  " + s.Name);
                }
                DataIO.UserWrite();
                return;
            }
        }
    }//从Userdata的数据中删除指定ID的用户

    public void AdminCancelStudentExpectUserdata(String id) throws IOException {
        //满足id的用户一定存在
        //从scoredata中删除
        Score score;
        for(int i = 0;i<DataField.scoreData.size();i++){//一个学生可能有多个score
            score = DataField.scoreData.get(i);
            if(score.StudentID.equals(id)){
                DataField.scoreData.remove(i);
                i-=1;//一定要减，不然会跳过一个结点
            }
        }
        //从studentdata中删除
        Student student;
        for(int i = 0;i<DataField.studentData.size();i++){
            student = DataField.studentData.get(i);
            if(student.ID.equals(id)){
                DataField.studentData.remove(i);
                break;
            }
        }

        DataIO.ScoreWrite();//保存到文件
        DataIO.StudentWrite();//保存到文件

        System.out.println("删除后，学生列表（只显示姓名和学号）：");
        for(Student s:DataField.studentData){
            System.out.println("姓名："+s.Name+"  学号："+s.ID);
        }//找到这个教师教授的科目
        System.out.println("学生列表显示完毕");

        System.out.println("删除后，Score列表：");
        for(Score sc:DataField.scoreData){
            System.out.println("课名："+sc.CourseName+"  教师："+sc.TeacherName+"  学生名："+sc.StudentName+"  学号："+sc.StudentID);
        }//找到这个教师教授的科目
        System.out.println("Score列表显示完毕");

    }//从除了Userdata的数据中删除指定ID的学生

    public void AdminCancelTeacherExpectUserdata(String id) throws IOException {
        //满足id的用户一定存在
        ArrayList<String> teachcourse = new ArrayList<>();
        String teacherName = new String();
        //从teacherdata中删除
        Teacher teacher;
        for(int i =0 ;i<DataField.teacherData.size();i++){
            teacher = DataField.teacherData.get(i);
            if(teacher.ID.equals(id)){//找到这位教师
                teachcourse = teacher.teachCourse;
                teacherName = teacher.Name;
                DataField.teacherData.remove(i);//由于有break，不用i--
                break;
            }
        }//找到这个教师教授的科目

        //从scoredata中删除
        //【由于Score无教师id，只能通过找到teacherdata中他任教的所有课，根据课名+教师姓名找到对应的结点，删除】
        Score score;
        for(int i = 0;i<DataField.scoreData.size();i++){
            score = DataField.scoreData.get(i);
            if(StringNotExistInArraylist(score.CourseName,teachcourse) == false &&
                    score.TeacherName.equals(teacherName)){
                //如果这个score的课程被老师所教，并且任课老师就是这个老师的名字，删除这个score结点,而且一定要i--
                DataField.scoreData.remove(i);
                i-=1;//一定要i--，因为下一个的内容已经移到目前这个来了，不i--的话会跳过一个score结点
            }
        }

        DataIO.TeacherWrite();//保存到文件
        DataIO.ScoreWrite();//保存到文件

        System.out.println("删除后，教师列表（只显示姓名）：");
        for(Teacher t:DataField.teacherData){
            System.out.println(t.Name);
        }//找到这个教师教授的科目
        System.out.println("教师列表显示完毕");

        System.out.println("删除后，Score列表：");
        for(Score sc:DataField.scoreData){
            System.out.println("课名："+sc.CourseName+"  教师："+sc.TeacherName+"  学生名："+sc.StudentName+"  学号："+sc.StudentID);
        }//找到这个教师教授的科目
        System.out.println("Score列表显示完毕");

    }//从除了Userdata的数据中删除指定ID的教师【未完成，新增用户协议：不能出现同名教师】

    public void AdminCancelAccountAction() throws IOException {
        //检查是否存在，若不存在，查无此人，如果找到，根据用户类型进行处理
        String id = AdminAddCourseOrMajorOrGradeOrWhitelistTextField.getText();
        if(id.equals("")){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("输入为空，请重新输入");
            return;
        }
        User user;
        for(int i =0;i<DataField.userData.size();i++){
            user = DataField.userData.get(i);
            if(user.ID.equals(id)){//找到这个用户
                System.out.println("找到用户");
                openTipWindows("注销该用户会从系统中删除其所有信息\n您确定要注销吗？","注销","返回");//
                if(TipChoose == true){//确定要删除
                    if(user.UserKind.equals("1")){//如果是学生
                        DataField.userData.remove(i);//在User中删除该用户
                        for(User s:DataField.userData){
                            System.out.println("帐号信息："+s.ID+"  "+s.Name);
                        }
                        DataIO.UserWrite();
                        AdminCancelStudentExpectUserdata(id);
                        AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("删除成功");
                    }
                    else if(user.UserKind.equals("2")){//如果是教师
                        DataField.userData.remove(i);//在User中删除该用户
                        for(User s:DataField.userData){
                            System.out.println("帐号信息："+s.ID+"  "+s.Name);
                        }
                        DataIO.UserWrite();
                        AdminCancelTeacherExpectUserdata(id);
                        AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("删除成功");
                    }
                    else if(user.UserKind.equals("0")){//如果是管理员
                        AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("对不起，无法删除管理员");
                    }
                }//if true
                else{
                    AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("取消删除");
                }
                return;
            }//if find
        }//for
        AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("对不起，查无此人");
    }//注销帐号Action

    public void AdminCancelAccount(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setVisible(true);//可见
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setDisable(false);//可用
            AdminAddCourseOrMajorOrGradeOrWhitelistText.setText("帐号：");
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("");
            AdminAddCourseOrMajorOrGradeOrWhitelistTextField.setPromptText("请输入需要注销的帐号");
            AdminAddCourseOrMajorOrGradeOrWhitelistButton.setOnAction(e-> {
                try {
                    AdminCancelAccountAction();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            });
            System.out.println("管理员注销用户");
        }
        //如果不是管理员，什么都不能做
    }//注销帐号

    //添加白名单
    public void AdminAddWhitelistAction(){
        //检查是否存在，若不存在，添加入whitelist中，然后写入一遍whitelist
        String id = AdminAddCourseOrMajorOrGradeOrWhitelistTextField.getText();
        if(id.equals("")){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("输入为空，请重新输入");
            return;
        }
        String tmp;
        int count = 0;
        for(int i = 0; i<DataField.whiteList.size(); i++){
            tmp = DataField.whiteList.get(i);
            if(tmp.equals(id)){
                count++;
            }
        }
        if(count>0){
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("此用户已在白名单中");
        }
        else{
            DataField.whiteList.add(id);
            DataField.whiteList.sort(new Comparator<String>() {
                @Override
                public int compare(String o1, String o2) {
                    return o1.compareTo(o2);
                }
            });
            try{
                DataIO.WhiteListWrite();
            }
            catch (IOException e){ System.out.println("whitelist.txt写入失败"+e); }
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("账户  "+id+"  成功添加入白名单内");
        }
    }//添加白名单Action

    public void AdminAddWhitelist(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setVisible(true);//可见
            AdminAddCourseOrMajorOrGradeOrWhitelistPane.setDisable(false);//可用
            AdminAddCourseOrMajorOrGradeOrWhitelistText.setText("帐号：");
            AdminAddCourseOrMajorOrGradeOrWhitelistTipText.setText("");
            AdminAddCourseOrMajorOrGradeOrWhitelistTextField.setPromptText("请输入需要添加进白名单的帐号");
            AdminAddCourseOrMajorOrGradeOrWhitelistButton.setOnAction(e->AdminAddWhitelistAction());
            System.out.println("管理员添加白名单");
        }
        //如果不是管理员，什么都不能做
    }//添加白名单

    //删除白名单
    public void AdminDelIdFromWhitelist(String id) throws IOException {
        String tmp;
        for(int i = 0;i<DataField.whiteList.size();i++){//从whitelist中删除
            tmp = DataField.whiteList.get(i);
            if(tmp.equals(id)){//找到这个id，删除
                DataField.whiteList.remove(i);
                break;//break for
            }
        }//for
        DataIO.WhiteListWrite();
    }//从whitelist中删除id

    public void AdminDelIdFromWhitelistdataObservableList(String id) throws IOException {
        WhitelistData tmp;
        for(int i = 0;i<WhitelistdataObservableList.size();i++){//从whitelist中删除
            tmp = WhitelistdataObservableList.get(i);
            if(tmp.getID().equals(id)){//找到这个id，删除
                WhitelistdataObservableList.remove(i);
                break;//break for
            }
        }//for
        DataIO.WhiteListWrite();
    }//从WhitelistdataObservableList中删除id

    public void AdminDelWhitelist() throws IOException {
        int x = AdminWatchWhitelistTableView.getSelectionModel().getFocusedIndex();//默认选中为0，即第一行
        WhitelistData whitelistData = WhitelistdataObservableList.get(x);

        if(whitelistData.getRegistered().equals("已注册")){//如果已经注册，弹出提示
            openTipWindows("帐号\""+whitelistData.getID()+"\"已注册\n是否要销户并解除白名单","是","否");
            if(TipChoose == true){//确认删除
                User user;
                for(int i = 0;i<DataField.userData.size();i++){//销户
                    user = DataField.userData.get(i);
                    if(user.ID.equals(whitelistData.getID())){//找到这个用户，删除
                        if(user.UserKind.equals("1")){//如果是学生
                            AdminCancelStudentExpectUserdata(whitelistData.getID());//从user以外的地方删除
                        }
                        else if(user.UserKind.equals("2")){//如果是老师
                            AdminCancelTeacherExpectUserdata(whitelistData.getID());//从user以外的地方删除
                        }
                        else if(user.UserKind.equals("0")){//如果是管理员
                            AdminWatchWhitelistTipText.setText("无法删除管理员的白名单权限！");
                            return;//结束方法的执行
                        }
                        DataField.userData.remove(i);//从user中删除
                        DataIO.UserWrite();
                        break;//break for
                    }
                }//for销户
            }//确认删除
            else{//取消删除
                AdminWatchWhitelistTipText.setText("取消删除");
                return;
            }
        }//如果已经注册，弹出提示
        //如果能到这，证明
        //1.已注册，确认删除，并且不是管理员
        //2.未注册
        AdminDelIdFromWhitelist(whitelistData.getID());
        AdminDelIdFromWhitelistdataObservableList(whitelistData.getID());
        AdminWatchWhitelistTipText.setText("帐号"+whitelistData.getID()+"删除成功");

    }//删除选中用户的白名单权限
    //查看白名单列表
    public final ObservableList<WhitelistData> WhitelistdataObservableList = FXCollections.observableArrayList();

    public void InitAdminWatchWhitelistTableView(){
        //设置六列，将数据关联到表中的列
        AdminWatchWhitelistIDTableColumn.setCellValueFactory(new PropertyValueFactory<>("ID"));//第一列中的数据关联UserData中的StudentID
        AdminWatchWhitelistRegisteredTableColumn.setCellValueFactory(new PropertyValueFactory<>("Registered"));//第二列中的数据关联SUserData中的PW

        AdminWatchWhitelistTableView.setItems(WhitelistdataObservableList);//数据关联到tableView
    }//初始化表格

    public void SearchforWhitelistTable(){
        //把User的所有信息都add进data里
        WhitelistdataObservableList.clear();
        String tmp;
        for(int i = 0; i<DataField.whiteList.size(); i++){
            tmp = DataField.whiteList.get(i);//得到ID
            boolean registered = false;
            User user;
            for(int j = 0;j<DataField.userData.size();j++){//验证注册情况
                user = DataField.userData.get(j);
                if(user.ID.equals(tmp)){//这个user的ID == 白名单账户，证明已注册
                    registered = true;
                }
            }
            WhitelistData whitelistData;
            if(registered == false){//如果没被注册
                whitelistData = new WhitelistData(tmp,"尚未注册");
            }
            else{//如果被注册
                whitelistData = new WhitelistData(tmp,"已注册");
            }
            WhitelistdataObservableList.add(whitelistData);//把学生信息添加进表格关联的list中
        }
        AdminWatchWhitelistTipText.setText("共有"+DataField.whiteList.size()+"个白名单ID");
    }//为白名单表格搜索数据

    public void AdminWatchWhitelist(){
        InitPanes();//所有的pane设为不可见不可用
        if(DataField.LoginedUser.UserKind.equals("0")){
            AdminWatchWhitelistPane.setVisible(true);//可见
            AdminWatchWhitelistPane.setDisable(false);//可用
            AdminWatchWhitelistTipText.setText("");
            AdminWatchWhitelistLeftButton.setText("添加白名单");
            AdminWatchWhitelistLeftButton.setOnAction(e->AdminAddWhitelist());//关闭页面，准备添加白名单页面
            AdminWatchWhitelistRightButton.setText("删除选中ID");
            AdminWatchWhitelistRightButton.setOnAction(e-> {
                try {
                    AdminDelWhitelist();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            });
            InitAdminWatchWhitelistTableView();
            SearchforWhitelistTable();
            System.out.println("管理员查看白名单列表");
        }
        //如果不是管理员，什么都不能做
    }//查看白名单列表





    public void setWelcomeText(){
        if(DataField.LoginedUser.UserKind.equals("0")){
            userIDText.setText(DataField.LoginedUser.Name);
        }
        else if (DataField.LoginedUser.UserKind.equals("1")){
            userIDText.setText(DataField.LoginedUser.Name);
        }
        else {
            userIDText.setText(DataField.LoginedUser.Name);
        }
    }

    public void InitPanes(){//所有pane都变成不可见不可用，每次点击菜单按钮时都要对本页面的控件进行更新
        //用户修改密码的Pane
        ChangePasswordPane.setVisible(false);//不可见
        ChangePasswordPane.setDisable(true);//不可用
        //用户修改密保问题的VBOX
        ChangeInitQuestionAndInitAnswerVBox.setVisible(false);//不可见
        ChangeInitQuestionAndInitAnswerVBox.setDisable(true);//不可用
        //教师添加、删除课程的pane
        TeacherAddCoursePane.setVisible(false);//不可见
        TeacherAddCoursePane.setDisable(true);//不可用
        //教师添加、删除学生的pane
        TeacherAddStudentPane.setVisible(false);//不可见
        TeacherAddStudentPane.setDisable(true);//不可用
        //教师录入、打印学生学生成绩的pane
        TeacherInputOrPrintStudentScorePane.setVisible(false);//不可见
        TeacherInputOrPrintStudentScorePane.setDisable(true);//不可用
        //管理员添加课程、专业、年级、白名单的pane
        AdminAddCourseOrMajorOrGradeOrWhitelistPane.setVisible(false);//不可见
        AdminAddCourseOrMajorOrGradeOrWhitelistPane.setDisable(true);//不可用
        //管理员添加班级的pane
        AdminAddClassPane.setVisible(false);//不可见
        AdminAddClassPane.setDisable(true);//不可用
        //管理员删除年级、专业、课程、用户的pane
        AdminDelCoursePane.setVisible(false);//不可见
        AdminDelCoursePane.setDisable(true);//不可用
        //管理员查看用户信息的界面
        AdminWatchUserInformationPane.setVisible(false);//不可见
        AdminWatchUserInformationPane.setDisable(true);//不可用
        //管理员查看白名单，删除白名单的界面
        AdminWatchWhitelistPane.setVisible(false);//不可见
        AdminWatchWhitelistPane.setDisable(true);//不可用

    }


    @Override
    public void initialize(URL location, ResourceBundle resources) {//初始化函数在执行FXMLLoader时执行
        setWelcomeText();
        InitPanes();
    }

}